import { http } from '@/request/http'
import type { PageDTO, PageVO } from '@/type/type'
import type { MakeOptional } from '@/type'

export type LabelVO = {
  // 自增主键
  id: number
  // 类别ID
  classifyId: number
  // 类别
  classifyName: string
  // 标签名
  name: string
  // 简介
  introduction: string
  // 状态
  status: boolean
}

export type LabelDTO = MakeOptional<LabelVO>

export const initLabelDTO = (): LabelDTO => {
  return {
    id: undefined,
    classifyId: undefined,
    name: undefined,
    introduction: undefined,
    status: undefined
  }
}

export const initLabelVO = (): LabelVO => {
  return {
    id: 0,
    classifyId: 0,
    classifyName: '',
    name: '',
    introduction: '',
    status: true
  }
}

export const labelVO2DTO = (vo: LabelVO): LabelDTO => {
  return {
    id: vo.id,
    classifyId: vo.classifyId,
    name: vo.name,
    introduction: vo.introduction,
    status: vo.status
  }
}

export const getLabelListByClassifyIdApi = (id: number) => {
  return http<LabelVO[]>({
    url: `/label/list/classify/${id}`,
    method: 'get'
  })
}

export const getLabelListByClassifyTypeApi = (type: number) => {
  return http<LabelVO[]>({
    url: `/label/list/classify/type/${type}`,
    method: 'get'
  })
}

export const getLabelAdminPageApi = (dto: PageDTO) => {
  return http<PageVO<LabelVO>>({
    url: `/admin/label/page`,
    method: 'get',
    params: {
      dto: JSON.stringify(dto)
    }
  })
}

export function addLabelApi(data: LabelDTO) {
  return http<boolean>({
    url: '/admin/label/insert',
    method: 'POST',
    data: data
  })
}

// 修改
export function updateLabelApi(data: LabelDTO) {
  return http<boolean>({
    url: '/admin/label/update',
    method: 'PUT',
    data: data
  })
}

// 删除
export function delLabelApi(ids: number[]) {
  return http<boolean>({
    url: '/admin/label/delete',
    method: 'DELETE',
    data: ids
  })
}
